package com.yh.homestay.controller;

import com.yh.homestay.aop.SystemLog;
import com.yh.homestay.common.HomeStayResult;
import com.yh.homestay.pojo.CapitalItem;
import com.yh.homestay.service.CapitalItemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName CapitalRoomController
 * @Description 商品Controller
 * @Date 2020/1/2 9:07
 */
@RestController
@Api(description = "商品管理")
@RequestMapping(value = "/item")
public class CapitalItemController {

    @Autowired
    private CapitalItemService capitalItemService;

   /**
   * @Date: 2020/1/11 11:08
   * @Description: 展示商品信息
   * @param page
    * @param limit
    * @param itemName
   * @return: com.yh.homestay.common.HomeStayResult
   */
    @RequestMapping(value="/list",method = RequestMethod.GET)
    @SystemLog(methods="商品展示", module = "商品管理")
    @ApiOperation(value = "获取所有商品列表", notes = "获取所有商品信息或者模糊查询")
    public HomeStayResult findCapitalItemAll(Integer page, Integer limit, String itemName) {
        return capitalItemService.findAllCapitalItems(page,limit,itemName);
    }

   /**
   * @Date: 2020/1/11 11:09
   * @Description: 添加商品信息
   * @param capitalItem
   * @return: com.yh.homestay.common.HomeStayResult
   */
    @RequestMapping(value = "/add",method = RequestMethod.POST)
    @SystemLog(methods="添加商品", module = "商品管理")
    @ApiOperation(value = "添加商品", notes = "添加商品信息")
    public HomeStayResult addCapitalItem(CapitalItem capitalItem) {
        return capitalItemService.addCapitalItem(capitalItem);
    }

    /**
    * @Date: 2020/1/11 11:09
    * @Description: 页面回显
    * @param id
    * @return: com.yh.homestay.common.ItemEditResult
    */
    @RequestMapping(value = "/one/{id}", method = RequestMethod.POST)
    @ApiOperation(value = "回显商品信息", notes = "根据id进行回显商品信息")
    public HomeStayResult goEditCapitalItem(@PathVariable("id") Integer id) {
        return capitalItemService.selectOneCapitalItem(id);
    }

   /**
   * @Date: 2020/1/11 11:10
   * @Description: 更新页面信息
   * @param capitalItem
   * @return: com.yh.homestay.common.HomeStayResult
   */
   @RequestMapping(value = "/update",method = RequestMethod.POST)
   @SystemLog(methods = "修改商品", module = "商品管理")
   @ApiOperation(value = "修改商品", notes = "修改商品信息")
    public HomeStayResult editCapitalItem(CapitalItem capitalItem) {
        return capitalItemService.updateCapitalItem(capitalItem);
    }

   /**
   * @Date: 2020/1/11 11:10
   * @Description: 删除单个商品信息
   * @param itemId
   * @return: com.yh.homestay.common.HomeStayResult
   */
   @RequestMapping(value = "/delete", method = RequestMethod.POST)
   @SystemLog(methods = "删除商品", module = "商品管理")
   @ApiOperation(value = "删除商品", notes = "删除商品数据")
    public HomeStayResult delCapitalItem(Integer itemId) {
        return capitalItemService.delCapitalItem(itemId);
    }


    /**
    * @Date: 2020/1/11 11:13
    * @Description: 批量删除商品信息
    * @param itemIds
    * @return: com.yh.homestay.common.HomeStayResult
    */
    @RequestMapping(value = "/deleteBatch", method = RequestMethod.POST)
    @SystemLog(methods = "删除多个商品", module = "商品管理")
    @ApiOperation(value = "批量删除商品", notes = "批量删除商品信息")
    public HomeStayResult batchDelCapitalItem(String itemIds) {
        return capitalItemService.delBatchCapitalItem(itemIds);
    }

}
